package com.sitechasia.webx.components.xtable.customertag;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.jsp.JspException;

import org.extremecomponents.table.bean.Column;
import org.extremecomponents.table.bean.Row;
import org.extremecomponents.table.core.TableModel;
import org.extremecomponents.table.core.TableModelUtils;
import org.extremecomponents.table.tag.ColumnTag;
import org.extremecomponents.table.tag.TagUtils;
import org.extremecomponents.tree.TreeNode;

/**
*
* <p>版权所有：中企动力
* <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
* <p>功能描述：自定义column标签类，加入header的鼠标动作属性、自动判断对齐功能，数字右对齐，字符左对齐以及自动省略功能
*
* @author kuanglingxuan
* Created on 2007-9-30
*/
public class CeColumnTag extends ColumnTag {

	/**
	 * 功能描述：Column对象创建的时候被调用
	 */
	public void addColumnAttributes(TableModel model, Column column) {

		column.addAttribute("headerOnmouseover", TagUtils.evaluateExpressionAsString("headerOnmouseover",getHeaderOnmouseover(), this, pageContext));
		column.addAttribute("headerOnmouseout", TagUtils.evaluateExpressionAsString("headerOnmouseout",getHeaderOnmouseout(), this, pageContext));
		column.addAttribute("ignoreOmit", TagUtils.evaluateExpressionAsString("ignoreOmit",getIgnoreOmit(),this,pageContext));
		column.addAttribute("showTitle", TagUtils.evaluateExpressionAsString("showTitle",getShowTitle(),this,pageContext));
	}

	/**
	* 功能描述：列表生成每一列数据的时候调用一次
	*/
	public void modifyColumnAttributes(TableModel model, Column column) {
		processStyleClass(model,column);//为TD添加class默认属性,默认为：grid align_left if (column != null) { // null if view not allowed
        String property = column.getProperty();

        /*****begin 针以树bean 的cell格式化操作******/
		Object bean = TagUtils.getModel(this).getCurrentRowBean();
		Object propertyValue = null;
		if(bean instanceof TreeNode)
		{
			TreeNode node = (TreeNode) bean;
			propertyValue= TableModelUtils.getColumnPropertyValue(node.getBean(), property);
		}
		else
		{
			propertyValue= TableModelUtils.getColumnPropertyValue(bean, property);
		}
        try {
			column.setValue(getColumnValue(propertyValue));
		} catch (JspException e) {
			e.printStackTrace();
		}
        column.setPropertyValue(propertyValue);
        /*****end******/
	}

	/**
	 *
    * Function:处理表格列的默认class属性。在UI中，td的默认class为grid align_left。
    * 在extreme table组件没处理默认值情况, 在这里添加上默认值。
    * Create author:yixianjian
    * Create on:2008-5-15
	 */
	private void processStyleClass(TableModel model, Column column){
		String styleClass = column.getStyleClass();
		String defaultStyleClass = styleClass != null? styleClass : model.getPreferences().getPreference("column.styleClass");
		column.setStyleClass(defaultStyleClass);
	}
	private String headerOnmouseover;

	private String headerOnmouseout;

	private String ignoreOmit;

	//是否显示td的title属性
	private String showTitle = "true";

	public String getIgnoreOmit() {
		return ignoreOmit;
	}

	public void setIgnoreOmit(String ignoreOmit) {
		this.ignoreOmit = ignoreOmit;
	}

	public String getHeaderOnmouseout() {
		return headerOnmouseout;
	}

	public void setHeaderOnmouseout(String headerOnmouseout) {
		this.headerOnmouseout = headerOnmouseout;
	}

	public String getHeaderOnmouseover() {
		return headerOnmouseover;
	}

	public void setHeaderOnmouseover(String headerOnmouseover) {
		this.headerOnmouseover = headerOnmouseover;
	}

	public String getShowTitle() {
		return showTitle;
	}

	public void setShowTitle(String showTitle) {
		this.showTitle = showTitle;
	}

}
